const fp = require('lodash/fp')
const {Maybe,Container} = require('./support')
//练习1
let maybe = Maybe.of([5,6,11])
let ex1 = (x)=>{
  return maybe.map(fp.map(a=>fp.add(a,x)))
}
console.log(ex1(2))// Maybe { _value: [ 7, 8, 13 ] }

//练习2
let xs = Container.of(['do','ray','me','fa','so','la','ti','do'])
let ex2 = ()=>{
  return xs.map(fp.first)
}
console.log(ex2()) // Container { _value: 'do' } 

//练习3
let safeProp = fp.curry(function(x,o){
  return Maybe.of(o[x])
})
let user = {id:2,name:'Albert'}
let ex3 = () =>{
  return safeProp('name',user).map(fp.first)
}
console.log(ex3()) // Maybe { _value: 'A' }

//练习4
let ex4 =(n)=> Maybe.of(n).map(parseInt)
console.log(ex4(2)) // Maybe { _value: 2 }
console.log(ex4(null)) // Maybe { _value: null }